package f;

import java.io.File;

import v4.file.FileJm;
import v4.file.FileJmConfig;

public interface Op {
	
	int add(File old);
	int delete(File jm);
	boolean backOne(File jm, File to);
	
	public static final class Kit {
		
		private File from;
		private File jmFile;
		private FileJmConfig config;
		
		public Kit(File from, File jmFile, FileJmConfig config) {
			this.from = from;
			this.jmFile = jmFile;
			this.config = config;
		}
		
		public boolean startJm(String key) {
			String f_ext = FileExt.getExt(from);
			String f_type = FileExt.getType(f_ext);
			String f_path = Root.getFPath(jmFile);
			if(f_path!=null) {
				FileJm jm = new FileJm(from, jmFile, config);
				String f_key = jm.encrypt(key);
				String f_hash = jm.getFromHash();
				String t_hash = jm.getToHash();
				if(f_key!=null && f_hash!=null && f_path!=null && t_hash!=null) {
					if(f_ext==null) {
						f_ext = "";
					}
					Db.defaultDb().insert(f_type, f_hash, f_path, f_ext, f_key, t_hash);
					return true;
				}
			}
			return false;
		}
	}
	
}
